<%@ page language="java" contentType="text/html; charset=UTF-8"
         pageEncoding="UTF-8"%>
<%@taglib prefix="mvc" uri="http://www.springframework.org/tags/form" %>
<%@taglib prefix="fmt" uri="http://www.springframework.org/tags" %>
<%
    String path = request.getContextPath();
    String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <title>节假日设置</title>
    <link rel="stylesheet" type="text/css" href="../lib/laydate.css"/>
    <link rel="stylesheet" type="text/css" href="../lib/pagination/style/pagination.css"/>
    <link rel="stylesheet" type="text/css" href="../css/base.css"/>
    <script type="text/javascript" src="../js/common/language.js" ></script>
    <script type="text/javascript" src="../js/news/jquery-1.9.1.js"></script>
    <script src="/lib/jQuery-File-Upload-master/jquery.ui.widget.js" type="text/javascript" charset="utf-8"></script>
    <script src="/lib/jQuery-File-Upload-master/jquery.iframe-transport.js" type="text/javascript" charset="utf-8"></script>
    <script src="/lib/jQuery-File-Upload-master/jquery.fileupload.js" type="text/javascript" charset="utf-8"></script>
    <script src="../js/news/page.js"></script>
    <script src="/lib/layer/layer.js?20201106"></script>
    <script src="/js/base/base.js"></script>
    <script src="/lib/laydate/laydate.js"></script>
    <script src="/js/ajaxupload.js" type="text/javascript" charset="utf-8"></script>
    <script src="/lib/jquery.form.min.js"></script>
    <script src="../lib/pagination/js/jquery.pagination.min.js" type="text/javascript" charset="utf-8"></script>
    <%--<script src="../lib/layer/layer.js?20201106"></script>--%>
    <style>
        a{
            text-decoration: none;
            color: #207bd6;
        }

        .buttonDiv>div{
            float: left;
            margin: 20px 10px;
        }
        .fileDone select{
            width: 160px;
            height:28px;
        }
        #tr_td tr:nth-child(odd){
            background-color: #fff;
        }
        input{
            float: none;
        }
        .newMange input[type="text"]{
            width: 260px;
            height: 30px;
        }
        select{
            width: 260px;
            height: 30px;
        }
        textarea{
            width: 260px;
            height: 50px;
            vertical-align: middle;
        }
        a{
            text-decoration: none;
            color: #207bd6;
        }
        .newTbale tr td{
            border-right: #ccc 1px solid;
            padding: 5px;
        }
        .divTable{
            width: 60%;
            margin: 0px auto;
        }
        .divTable table{
            width: 100%;
        }
        .divTable table tr th{
            padding: 8px;
            font-size: 13pt;
            color: #2F5C8F;
        }
        .divTable table tr td{
            text-align: center;
        }
        .divBtn{
            float: right !important;
            width: 103px;
            height: 28px;
            background: #2b7fe0;
            color: #fff;
            font-size: 14px;
            line-height: 28px;
            margin-right: 4%;
            margin-top: 20px;
            cursor: pointer;
            border-radius: 4px;
        }
        .divNew{
            width: 100%;
            overflow: hidden;
        }
        .divNew table{
            width: 82%;
            margin: 20px auto;
        }
        .divNew table tr{
            border: none;
        }
        .divNew table tr td:first-of-type{
            white-space:nowrap;
            width: 100px;
        }
        .divNew table tr td input{
            width: 180px;
            height: 28px;
            border-radius: 5px;
            padding-left: 5px;
        }
        .divNew table tr td textarea{
            width: 180px;
            height: 50px;
            border-radius: 5px;
            padding-left: 5px;
        }
        .return{
            width: 103px;
            height: 28px;
            background: #2b7fe0;
            border-radius: 4px;
            cursor: pointer;
            text-align: center;
            color: #ffffff;
            line-height: 28px;
            float: right;
            font-size: 14px;
            margin: 20px 70px 0 0;
        }
        .return a{
            color: #ffffff;
            padding:0 30px;
        }
        .add{
            padding-left: 5px;
            color: #207bd6;
            cursor:pointer;
        }
        .clear{
            color:#f00;
            cursor:pointer;
            padding-left: 5px;
        }

    </style>
</head>

<body>
<div class="bx">

    <div class="navigation  clearfix juMange" id="hoSet" style="display: block;">
        <div class="left" style="margin-left: 30px">
            <img src="/img/commonTheme/${sessionScope.InterfaceModel}/icon_manageFile.png">
            <div class="news">节假日设置</div>
        </div>
        <div class="return"><a href="/attendanceWay/attindex">返回</a></div>
        <div class="divBtn">
            <img src="../../img/mywork/newbuildworjk.png" alt="" style="margin-left: 6px;margin-top: -4px;">
            <span style="font-size: 11pt;">添加节假日</span>
        </div>
        <div style="clear: both;"></div>
        <div class="divTable" style="display: block;">
            <table border="0" cellpadding="0" cellspacing="0" style="border-collapse: collapse">
                <thead>
                <tr>
                    <th>序号</th>
                    <th>节假日名称</th>
                    <th>起始日期</th>
                    <th>结束日期</th>
                    <th>操作</th>
                </tr>
                </thead>
                <tbody id="trList">

                </tbody>
            </table>
            <%--<div class="right">--%>
                <%--<!-- 分页按钮-->--%>
                <%--<div class="M-box3" id="dbgz_page"></div>--%>
            <%--</div>--%>
        </div>

    </div>
</div>
<script type="text/javascript">
    $(function () {
//        数据初始化
        dataList($('#trList'));
//        新建
        $('.divBtn').click(function () {
            layer.open({
                type: 1,
                title:['添加节假日', 'background-color:#2b7fe0;color:#fff;'],
                area: ['485px', '500px'],
                shadeClose: true, //点击遮罩关闭
                btn: ['添加', '取消'],
                scrollbar: false,
                content:'<div class="divNew">' +
                '<table border="0" cellpadding="0" cellspacing="0" style="border-collapse: collapse">' +
                '<tr>' +
                '<td>起始日期：</td>' +
                '<td><input type="text" name="beginDate" value="" onclick="laydate({istime: true, format: \'YYYY-MM-DD\'})"></td>' +
                '</tr>' +
                '<tr>' +
                '<td>结束日期：</td>' +
                '<td><input type="text" name="endDate" value="" onclick="laydate({istime: true, format: \'YYYY-MM-DD\'})"></td>' +
                '</tr>' +
                '<tr>' +
                '<td>节假日名称：</td>' +
                '<td><input type="text" name="holidayName" value=""></td>' +
                '</tr>' +
                '<tr>' +
                '<td>人员：</td>' +
                '<td><textarea name="user" id="query_userId" disabled></textarea>' +
                '<span class="add" id="query_adduser">添加</span>' +
                '<span class="clear" id="clearUser">清空</span></td>' +
                '</tr>' +
                '<tr>' +
                '<td>部门：</td>' +
                '<td><textarea name="user" id="DEPT_NAME"  disabled></textarea>' +
                '<span class="add" id="dept_add">添加</span>' +
                '<span class="clear" id="clearDept">清空</span></td>' +
                '</tr>' +
                '<tr>' +
                '<td>角色：</td>' +
                '<td><textarea name="user" id="USER_PRIV_NAME" disabled></textarea>' +
                '<span class="add" id="userPriv_add">添加</span>' +
                '<span class="clear" id="clearPriv">清空</span></td>' +
                '</tr>' +
                '</table>' +
                '</div>',
                success:function () {
                    $('input[name="beginDate"]').val(queryTime());
                    $('input[name="endDate"]').val(queryTime());
                    //选部门
                    $('#dept_add').on("click", function () {
                        dept_id = 'DEPT_NAME';
                        $.popWindow("../../../common/selectDept?0");
                    });
                    $('#clearDept').on("click", function () {
                        $("#DEPT_NAME").val("");
                        $('#DEPT_NAME').attr('deptid','')
                        $('#DEPT_NAME').attr('deptname','')
                    });
                    //选角色
                    $('#userPriv_add').on("click", function () {
                        priv_id = 'USER_PRIV_NAME';
                        $.popWindow("../../../common/selectPriv?0");
                    });
                    $('#clearPriv').on("click", function () {
                        $("#USER_PRIV_NAME").val("");
                        $('#USER_PRIV_NAME').attr('privid','')
                        $('#USER_PRIV_NAME').attr('userpriv','')
                    });
                    //选人员
                    $("#query_adduser").on("click", function () {
                        user_id = 'query_userId';
                        $.popWindow("../../../common/selectUser");
                    });
                    $('#clearUser').on("click", function () {
                        $("#query_userId").val("");
                        $('#query_userId').attr('username','')
                        $('#query_userId').attr('user_id','')
                        $('#query_userId').attr('dataid','')
                        $('#query_userId').attr('userprivname','')
                    });
                },
                yes:function (index) {
                    if($('input[name="beginDate"]').val() == ''){
                        layer.msg('请输入起始日期！', {icon: 1});
                        return false;
                    }
                    if($('input[name="endDate"]').val() == ''){
                        layer.msg('请输入结束日期！', {icon: 1});
                        return false;
                    }
                    if($('input[name="holidayName"]').val() == ''){
                        layer.msg('请输入节假日名称！', {icon: 1});
                        return false;
                    }
                    var startTime=new Date($('input[name="beginDate"]').val()).getTime()-new Date($('input[name="endDate"]').val()).getTime();
                    if(startTime > 0){
                        layer.msg('结束日期早于起始日期，请重新选择！', {icon: 1});
                        return false;
                    }
                    $.ajax({
                        type:'post',
                        url:'/attendHoliday/addHoliday',
                        dataType:'json',
                        data:{
                            deptId: $("#DEPT_NAME").attr("deptid"),//部门
                            privId: $("#USER_PRIV_NAME").attr("userpriv"),//角色
                            userId: $("#query_userId").attr("user_id"),//人员
                            beginDate:$('input[name="beginDate"]').val(),
                            endDate:$('input[name="endDate"]').val(),
                            holidayName:$('input[name="holidayName"]').val(),
                        },
                        success:function (res) {
                            if(res.flag){
                                $.layerMsg({content:'新建成功！',icon:1})
                                layer.close(index);
                                dataList($('#trList'));
                            }else{
                                $.layerMsg({content:'新建失败！',icon:2})
                            }
                        }
                    })

                },
            })
        });

//        编辑
        $('#trList').on('click','.editData',function () {
            var hoId=$(this).parents('tr').attr('data-id');
            layer.open({
                type: 1,
                title:['添加节假日', 'background-color:#2b7fe0;color:#fff;'],
                area: ['485px', '500px'],
                shadeClose: true, //点击遮罩关闭
                btn: ['添加', '取消'],
                content:'<div class="divNew" >' +
                '<table border="0" cellpadding="0" cellspacing="0" style="border-collapse: collapse">' +
                '<tr>' +
                '<td>起始日期：</td>' +
                '<td><input type="text" name="beginDate" value="" onclick="laydate({istime: true, format: \'YYYY-MM-DD\'})"></td>' +
                '</tr>' +
                '<tr>' +
                '<td>结束日期：</td>' +
                '<td><input type="text" name="endDate" value="" onclick="laydate({istime: true, format: \'YYYY-MM-DD\'})"></td>' +
                '</tr>' +
                '<tr>' +
                '<td>节假日名称：</td>' +
                '<td><input type="text" name="holidayName" value=""></td>' +
                '</tr>' +
                '<tr>' +
                '<td>人员：</td>' +
                '<td><textarea name="user" id="query_userId" disabled></textarea>' +
                '<span class="add" id="query_adduser">添加</span>' +
                '<span class="clear" id="clearUser">清空</span></td>' +
                '</tr>' +
                '<tr>' +
                '<td>部门：</td>' +
                '<td><textarea name="user" id="DEPT_NAME"  disabled></textarea>' +
                '<span class="add" id="dept_add">添加</span>' +
                '<span class="clear" id="clearDept">清空</span></td>' +
                '</tr>' +
                '<tr>' +
                '<td>角色：</td>' +
                '<td><textarea name="user" id="USER_PRIV_NAME" disabled></textarea>' +
                '<span class="add" id="userPriv_add">添加</span>' +
                '<span class="clear" id="clearPriv">清空</span></td>' +
                '</tr>' +
                '</table>' +
                '</div>',
                success:function () {
                    //选部门
                    $('#dept_add').on("click", function () {
                        dept_id = 'DEPT_NAME';
                        $.popWindow("../../../common/selectDept?0");
                    });
                    $('#clearDept').on("click", function () {
                        $("#DEPT_NAME").val("");
                        $('#DEPT_NAME').attr('deptid','')
                        $('#DEPT_NAME').attr('deptname','')
                    });
                    //选角色
                    $('#userPriv_add').on("click", function () {
                        priv_id = 'USER_PRIV_NAME';
                        $.popWindow("../../../common/selectPriv?0");
                    });
                    $('#clearPriv').on("click", function () {
                        $("#USER_PRIV_NAME").val("");
                        $('#USER_PRIV_NAME').attr('privid','')
                        $('#USER_PRIV_NAME').attr('userpriv','')
                    });
                    //选人员
                    $("#query_adduser").on("click", function () {
                        user_id = 'query_userId';
                        $.popWindow("../../../common/selectUser");
                    });
                    $('#clearUser').on("click", function () {
                        $("#query_userId").val("");
                        $('#query_userId').attr('username','')
                        $('#query_userId').attr('user_id','')
                        $('#query_userId').attr('dataid','')
                        $('#query_userId').attr('userprivname','')
                    });
                    $.ajax({
                        type:'get',
                        url:'/attendHoliday/selHolidayDetail',
                        dataType:'json',
                        data:{holidayId:hoId},
                        success:function (res) {
                            var datas=res.object;
                            $('input[name="beginDate"]').val(datas.beginDate);
                            $('input[name="endDate"]').val(datas.endDate);
                            $('input[name="holidayName"]').val(datas.holidayName);
                            $("#DEPT_NAME").val(datas.deptName);
                            $("#DEPT_NAME").attr('deptid',datas.deptId);
                            $("#USER_PRIV_NAME").val(datas.privName);
                            $("#USER_PRIV_NAME").attr('userpriv',datas.privId);
                            $("#query_userId").val(datas.userName);
                            $("#query_userId").attr('user_id',datas.userId);
                        }
                    })

                },
                yes:function (index) {
                    if($('input[name="beginDate"]').val() == ''){
                        layer.msg('请输入起始日期！', {icon: 1});
                        return false;
                    }
                    if($('input[name="endDate"]').val() == ''){
                        layer.msg('请输入结束日期！', {icon: 1});
                        return false;
                    }
                    if($('input[name="holidayName"]').val() == ''){
                        layer.msg('请输入节假日名称！', {icon: 1});
                        return false;
                    }
                    var startTime=new Date($('input[name="beginDate"]').val()).getTime()-new Date($('input[name="endDate"]').val()).getTime();
                    if(startTime > 0){
                        layer.msg('结束日期早于起始日期，请重新选择！', {icon: 1});
                        return false;
                    }
                    $.ajax({
                        type:'post',
                        url:'/attendHoliday/editHoliday',
                        dataType:'json',
                        data:{
                            deptId: $("#DEPT_NAME").attr("deptid"),//部门
                            privId: $("#USER_PRIV_NAME").attr("userpriv"),//角色
                            userId: $("#query_userId").attr("user_id"),//人员
                            holidayId:hoId,
                            beginDate:$('input[name="beginDate"]').val(),
                            endDate:$('input[name="endDate"]').val(),
                            holidayName:$('input[name="holidayName"]').val(),
                        },
                        success:function (res) {
                            if(res.flag){
                                $.layerMsg({content:'修改成功！',icon:1})
                                layer.close(index);
                                dataList($('#trList'));
                            }else{
                                console.log( $('input[name="holidayName"]').val())
                                $.layerMsg({content:'修改成功！',icon:1})
                                layer.close(index);
                                window.location.reload();
                                // $.layerMsg({content:'修改失败！',icon:2})
                            }
                        }
                    })

                },
            })
        });

//        删除
        $('#trList').on('click','.deleteData',function () {
            var hoId=$(this).parents('tr').attr('data-id');
            layer.confirm('确定要删除吗？', {
                btn: ['确定','取消'] //按钮
            }, function(index){
                $.ajax({
                    type:'post',
                    url:'/attendHoliday/delHoliday',
                    dataType:'json',
                    data:{holidayId:hoId},
                    success:function (res) {
                        if(res.flag){
                            layer.msg('删除成功！', {icon: 1,time:1000});
                            layer.close(index);
                            dataList($('#trList'));
                        }else{
                            layer.msg('删除失败！', {icon: 2,time:1000});
                            layer.close(index);
                        }
                    }
                })
            }, function(index){
                layer.closeAll();
            });
        })
    })

    function dataList(element) {
        $.ajax({
            type:'get',
            url:'/attendHoliday/selHoliday',
            dataType:'json',
            success:function (res) {
                var data=res.obj;
                var str='';
                if(data.length > 0){
                    for(var i=0;i<data.length;i++){
                        str+='<tr data-id="'+data[i].holidayId+'">' +
                            '<td>'+(i+1)+'</td>' +
                            '<td>'+data[i].holidayName+'</td>' +
                            '<td>'+data[i].beginDate+'</td>' +
                            '<td>'+data[i].endDate+'</td>' +
                            '<td><a href="javascript:;" class="editData" style="margin-right: 10px;">编辑</a><a style="color: crimson" href="javascript:;" class="deleteData">删除</a></td>' +
                            '</tr>';
                    }
                }
                element.html(str);
            }
        })
    }

    function queryTime(){
        function p(s) {
            return s < 10 ? '0' + s: s;
        }
        var myDate = new Date();
        //获取当前年
        var year=myDate.getFullYear();
        //获取当前月
        var month=myDate.getMonth()+1;
        //获取当前日
        var date=myDate.getDate();
        var h=myDate.getHours();       //获取当前小时数(0-23)
        var m=myDate.getMinutes();     //获取当前分钟数(0-59)
        var s=myDate.getSeconds();
        var now=year+'-'+p(month)+"-"+p(date);
        return now;
    }

</script>
</body>
</html>



